package newrelic

import (
	"bufio"
	"io"
	"net"
	"net/http"
)

func (txn *txn) CloseNotify() <-chan bool {
	return txn.getWriter().(http.CloseNotifier).CloseNotify()
}
func (txn *txn) Flush() {
	txn.getWriter().(http.Flusher).Flush()
}
func (txn *txn) Hijack() (net.Conn, *bufio.ReadWriter, error) {
	return txn.getWriter().(http.Hijacker).Hijack()
}
func (txn *txn) ReadFrom(r io.Reader) (int64, error) {
	return txn.getWriter().(io.ReaderFrom).ReadFrom(r)
}

func upgradeTxn(txn *txn) Transaction {
	// Note that txn.getWriter() is not used here.  The transaction is
	// locked (or under construction) when this function is used.

	// GENERATED CODE DO NOT MODIFY
	// This code generated by internal/tools/interface-wrapping
	var (
		i0 int32 = 1 << 0
		i1 int32 = 1 << 1
		i2 int32 = 1 << 2
		i3 int32 = 1 << 3
	)
	var interfaceSet int32
	if _, ok := txn.writer.(http.CloseNotifier); ok {
		interfaceSet |= i0
	}
	if _, ok := txn.writer.(http.Flusher); ok {
		interfaceSet |= i1
	}
	if _, ok := txn.writer.(http.Hijacker); ok {
		interfaceSet |= i2
	}
	if _, ok := txn.writer.(io.ReaderFrom); ok {
		interfaceSet |= i3
	}
	switch interfaceSet {
	default: // No optional interfaces implemented
		return struct {
			Transaction
		}{txn}
	case i0:
		return struct {
			Transaction
			http.CloseNotifier
		}{txn, txn}
	case i1:
		return struct {
			Transaction
			http.Flusher
		}{txn, txn}
	case i0 | i1:
		return struct {
			Transaction
			http.CloseNotifier
			http.Flusher
		}{txn, txn, txn}
	case i2:
		return struct {
			Transaction
			http.Hijacker
		}{txn, txn}
	case i0 | i2:
		return struct {
			Transaction
			http.CloseNotifier
			http.Hijacker
		}{txn, txn, txn}
	case i1 | i2:
		return struct {
			Transaction
			http.Flusher
			http.Hijacker
		}{txn, txn, txn}
	case i0 | i1 | i2:
		return struct {
			Transaction
			http.CloseNotifier
			http.Flusher
			http.Hijacker
		}{txn, txn, txn, txn}
	case i3:
		return struct {
			Transaction
			io.ReaderFrom
		}{txn, txn}
	case i0 | i3:
		return struct {
			Transaction
			http.CloseNotifier
			io.ReaderFrom
		}{txn, txn, txn}
	case i1 | i3:
		return struct {
			Transaction
			http.Flusher
			io.ReaderFrom
		}{txn, txn, txn}
	case i0 | i1 | i3:
		return struct {
			Transaction
			http.CloseNotifier
			http.Flusher
			io.ReaderFrom
		}{txn, txn, txn, txn}
	case i2 | i3:
		return struct {
			Transaction
			http.Hijacker
			io.ReaderFrom
		}{txn, txn, txn}
	case i0 | i2 | i3:
		return struct {
			Transaction
			http.CloseNotifier
			http.Hijacker
			io.ReaderFrom
		}{txn, txn, txn, txn}
	case i1 | i2 | i3:
		return struct {
			Transaction
			http.Flusher
			http.Hijacker
			io.ReaderFrom
		}{txn, txn, txn, txn}
	case i0 | i1 | i2 | i3:
		return struct {
			Transaction
			http.CloseNotifier
			http.Flusher
			http.Hijacker
			io.ReaderFrom
		}{txn, txn, txn, txn, txn}
	}
}
